package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import com.google.errorprone.annotations.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2023/1/11
 */
@RestController
@RequestMapping("tag")
public class TagController {

    @Autowired
    private TagService tagService;
    // 查询标签列表
    @GetMapping
    public List<Tag> tagList(){
        List<Tag> list = tagService.list();
        return list;
    }

    //添加标签
    @PostMapping
    public Tag tagList(Tag tag){
        tag.setCreatedate(new Date());
        tagService.save(tag);
        return tag;
    }

    //根据id删除标签
    @DeleteMapping("{id}")
    public String delete(@PathVariable Integer id){
        tagService.removeById(id);
        return "ok";
    }

    // 根据标签id 查询标签详细信息
    @GetMapping("{id}")
    public Tag getById(@PathVariable Integer id){
        Tag tag = tagService.getById(id);
        return tag;
    }

}
